package com.zmcn.fileTransfer.business.filetransfer.client;

import java.security.Key;
import java.util.Map;

import com.zmcn.fileTransfer.fw.util.AESCoder;
import com.zmcn.fileTransfer.fw.util.PropUtil;

public class Client {
	/**
	 * 目标地址
	 */
	private static String souUrl;
	/**
	 * 中转服务器地址
	 */
	private static String centerUrl;
	/**
	 * 登入帐号
	 */
	private static String account;
	/**
	 * 登入密码
	 */
	private static String pwd;
	/**
	 * 目标输出路径
	 */
	private static String aimPath;
	/**
	 * 切片临时存放路径
	 */
	private static String tempPath;
	/**
	 * 切片大小
	 */
	private static int size;
	/**
	 * 线程开启数
	 */
	private static int threadNum;
	/**
	 * 任务循环时间
	 */
	private static int sleepTime;

	/**
	 * 数据流密匙
	 */
	private static Key key;

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		// 读取参数
		Map<String, String> paras = PropUtil.read();
		souUrl = paras.get("souUrl");
		centerUrl = paras.get("centerUrl");
		account = paras.get("account");
		pwd = paras.get("pwd");
		aimPath = paras.get("aimPath");
		tempPath = paras.get("tempPath");
		size = Integer.parseInt(paras.get("size"));
		threadNum = Integer.parseInt(paras.get("threadNum"));
		sleepTime = Integer.parseInt(paras.get("sleepTime"));
		String flowPwd = paras.get("flowPwd");
		key = AESCoder.toKey(AESCoder.strToByte(flowPwd));
		System.out.println("==============>读取配置");

		// 执行任务
		new Thread(new Runnable() {
			public void run() {
				while (true) {
					try {
						new DownFile(souUrl, centerUrl, account, pwd, aimPath, tempPath, size, threadNum, key).start();
					} catch (Exception err) {
						err.printStackTrace();
					}
					try {
						Thread.sleep(sleepTime);
					} catch (InterruptedException e) {
					}
				}
			}
		}).start();

	}
}
